/* 
 * BookingTableModel.java 18.04.2011
 * $Revision$
 *  
 *  
 * Candidate: Alessandra Otterbach
 * Prometric ID: Algisina1
 * Username: Algisina
 *  
 * Sun Certified Developer for Java 2 Platform, Standard Edition Programming 
 * Assignment (CX-310-252A)
 *  
 * This class is part of the Programming Assignment of the Sun Certified 
 * Developer for Java 2 Platform, Standard Edition certification program, must 
 * not be used out of this context and must be used exclusively by Sun 
 * Microsystems, Inc. 
 */
package suncertify.ps;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import suncertify.dao.RoomRecord;

/**
 * 
 * @author Alessandra Otterbach
 * 
 */
public class BookingTableModel extends AbstractTableModel {

    protected List<RoomRecord> roomList = new ArrayList<RoomRecord>();
    protected List<String> columnList = new ArrayList<String>();

    public BookingTableModel(List<RoomRecord> rooms, List<String> columns) {
	this.roomList = rooms;
	this.columnList = columns;
    }

    /*
     * (non-Javadoc)
     * 
     * @see javax.swing.table.TableModel#getRowCount()
     */
    @Override
    public int getRowCount() {
	return roomList.size();
    }

    /*
     * (non-Javadoc)
     * 
     * @see javax.swing.table.TableModel#getColumnCount()
     */
    @Override
    public int getColumnCount() {
	return columnList.size();
    }

    /*
     * (non-Javadoc)
     * 
     * @see javax.swing.table.TableModel#getValueAt(int, int)
     */
    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
	RoomRecord room = (RoomRecord) roomList.get(rowIndex);
	
	switch (columnIndex) {
	case 0:
	    return room.getName();
	case 1:
	    return room.getLocation();
	case 2:
	    return room.getSize();
	case 3:
	    return room.getSmoking();
	case 4:
	    return room.getRate();
	case 5:
	    return room.getDate();
	case 6:
	    return room.getOwner();
	default:
	    return null;
	}
    }

    /*
     * (non-Javadoc)
     * 
     * @see javax.swing.table.AbstractTableModel#getColumnName(int)
     */
    @Override
    public String getColumnName(int column) {
	Object id = null;
	// This test is to cover the case when
	// getColumnCount has been subclassed by mistake ...
	if (column < columnList.size() && (column >= 0)) {
	    id = columnList.get(column);
	}
	return (id == null) ? super.getColumnName(column) : id.toString();
    }

    public RoomRecord getRoomAtSelectedRow(int row) {

	return roomList.get(row);

    }
    // public void addRow(RoomDao room) {
    //
    // }
}
